Graphical output under the Microsoft Windows 3.x.RTM. and Windows NT.RTM. operating systems is generally accomplished through calls to operating system functions. The operating system components used for carrying out graphics instructions are collectively referred to as the graphic device interface or GDI.
The Windows.RTM. GDI uses dynamically created objects or resources for carrying out drawing operations. Resources are classified into four different categories or classes: pens, brushes, palettes and fonts. One resource from each class can be currently selected at any given time. Different GDI resources are used to perform various types of drawing operations.
In general, resource-related GDI functions or instructions can be categorized as resource creation instructions, resource selection instructions, resource usage instructions, and resource deletion instructions. Before a resource is used it must be created with a resource creation instruction. It must then be selected using a resource selection instruction. Resource usage instructions are used to draw shapes with whatever resource has most recently been selected with a resource selection instruction. After use, resources are deleted with resource deletion instructions.
Resource usage instructions can be used to form a variety of shapes or images, such as lines, arcs, regions, ellipses, polygons, rectangles, and bitmaps. Drawing a straight line is an example of a simple operation that can be performed with GDI instructions. To draw a line, a pen is created, selected, used, and then deleted. This involves four different instructions or GDI function calls: CREATEPEN, SELECTOBJECT, LINETO, and DELETEOBJECT.
Some GDI instructions are dependent on previous instructions. For instance, resource selection instructions are dependent on previously issued resource creation instructions--before a resource can be selected it must be created. Similarly, resource usage instructions are dependent on previously issued resource creation and selection instructions--before a resource can be used it must be both created and selected.
Many GDI operations are also dependent on computer-maintained state information such as existing resources and their attributes, and graphics modes. State information includes such things as aspect ratio, pixel origin, background color, display mode, text color, text alignment, window origins, color adjustment, direction of polygon filling, view scaling, clipping, etc. In this discussion, state information also includes the identification of currently selected resources.
The combination of all current state information is referred to as a state context. The Windows.RTM. GDI maintains a context stack. The current state context can be pushed onto or popped from the stack. This provides an easy way for an application program to perform GDI operations without permanently changing the state context.
In addition to providing a convenient way to create device-independent graphics images, the Windows.RTM. GDI can be used to create data files for storing such images. Rather than storing the images in bit-mapped format, they are stored as an ordered sequence of GDI instructions which are "played" to create an actual display image. The Windows.RTM. GDI contains functions for recording and storing GDI instructions in such files, which are referred to in the Windows.RTM. environment as "metafiles." A metafile is simply a collection of GDI commands that creates desired text or images. Because metafiles take up less space and are more device-independent than bitmaps, they provide convenient storage for images that appear repeatedly in an application or need to be moved from one application to another.
To generate a metafile, a Windows.RTM. application creates a special device context that sends GDI commands to a metafile for storage. The application can later play back the metafile and display the image. During playback, the GDI breaks the metafile down into records, each containing an instruction, and identifies each created resource with an object index value that indexes a handle table. After a DELETEOBJECT instruction is encountered during playback, the associated object index value is re-used by the next resource that the metafile creates.
A metafile consists of two pertinent parts: a header and a list of records. The header contains a description of the size of the metafile, the number of drawing resources it uses, and other information. Each metafile record contains a header, a GDI instruction, and its arguments.
GDI functions and metafiles will be familiar to those accustomed to programming in the Windows.RTM. environment. For more information regarding these subjects, refer to the Windows 3.1.RTM. and Windows NT.RTM. Programming Manuals, available from Microsoft Corporation of Redmond, Wash. Both of these references are hereby incorporated by reference.
While metafiles offer an attractive alternative to bit-mapped files, further size reduction would be welcomed--particularly in the context of newer consumer-oriented applications which attempt to utilize graphical user interfaces to a degree that has previously not been attempted. The invention described below meets this need by reducing the number of records or instructions in metafiles. In addition, the methods described below result in optimized metafiles which can be played back more quickly than the original, non-optimized metafiles.